const BehaviorAll = require("../../../behaviors/behavior_all.js");
const ServiceScore = require("../../../service/service_score.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll],
  /**
   * 页面的初始数据
   */
  data: {
    /**
     * 积分记录相关
     */
    records:[],
    allScore: 0,
    /**
     * 购物车相关
     */
    car_amount: 0,
    triggerRetrieveData: false,
    /**
     * 其它
     */
    startPage: 0
  },

  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      // 加载数据
      ServiceScore.find(function (data) {
        _this.setData({
          allScore: data
        })
      })
      ServiceScore.page(_this.data.startPage, function (data) {
        _this.setData({
          records: data.records
        })
      });
    },
    /**
    * onShow
    */
    onShow: function (e) {
      const _this = this;
      _this.setData({ triggerRetrieveData: true });
    },

    /**
   * 获取数据
   */
    car_onRetrieve: function (e) {
      const _this = this;
      _this.setData({
        car_amount: e.detail.amount
      })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
      const _this = this;
      let startPage = _this.data.startPage + 1;
      ServiceScore.page(startPage, function (data) {
        _this.data.records.push(...data.records);
        _this.setData({
          records: _this.data.records,
          startPage: startPage
        });
      });
    }
  }

})